package com.chen.serivce.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.chen.entity.Student;
import com.chen.entity.vo.StudentVo;
import com.chen.mapper.StudentMapper;
import com.chen.serivce.StudentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
// 继承ServiceImpl,我们就不用实现IService的方法了, ServiceImpl帮我们实现好了
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService {
//    @Autowired
//    private StudentMapper studentMapper;
    @Override
    public List<Student> showAll() {
        //  因为继承了ServiceImpl , 可以直接写baseMapper , 不用注入了
        // 也可以直接用ServiceImpl 里面的方法, 比如
  //        getById()
         return   baseMapper.showAll();
//        return studentMapper.showAll() ;
    }


    @Override
    public List<Student> selectByMonth() {
        List<Student> studentList=baseMapper.selectByMonth();
        return  studentList;
    }

    @Override
    public PageInfo<Student> selectByPage(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Student> studentList =baseMapper.showAll();
        //对日期格式化
//        List<Student> collect = studentList.stream().map(item -> {
//            Date date = item.getSbirthdate();
//            Date newDate = null;
//            try {
//                System.out.println(String.valueOf(date));
////                newDate = DateUtils.parseDate(String.valueOf(date), "yyyy-MM-dd");
//            } catch (Exception e) {
//                throw new RuntimeException(e);
//            }
//            item.setSbirthdate(newDate);
//            return item;
//        }).collect(Collectors.toList());
        return new PageInfo<>(studentList);
    }

    @Override
    public List<Student> getByOne() {
        List<Student> students= baseMapper.selectCs();
        return students;
    }

    /**
     * 第二题
     * @return
     */
    @Override
    public List<StudentVo> getBytwo() {
        return baseMapper.selectByTwo();
    }

    /**
     * 根据学生名字查学分
     * @param name
     * @return
     */
    @Override
    public List<Map<String,Object>> getCreditByName(String name) {
        return baseMapper.selectCreditByName(name);
    }


}